package com.damai.generate;

import java.util.Map;

import com.citywithincity.utils.StringUtils;

public class ReactGenerateUtil {
	public static String join(String[] args){
		StringBuilder sb = new StringBuilder();
		boolean first = true;
		for (String string : args) {
			if(first){
				first = false;
			}else{
				sb.append(",");
			}
			sb.append('"');
			sb.append(string);
			sb.append('"');
		}
		return sb.toString();
	}
	
	
	public static String packArray(String src){
		return new StringBuilder().append("[").append(src).append("]").toString();
	}
	
	public static String getSelectValues(Map<String, String> extra){
		String values = extra.get("values");
		String[] valuesArray = values.split(",");
		String type = extra.get("type");
		if("int".equalsIgnoreCase(type)){
			return StringUtils.join(valuesArray);
		}else{
			return join(valuesArray);
		}
	}
	
	public static String getSelectLabels(Map<String, String> extra){
		String values = extra.get("labels");
		String[] valuesArray = values.split(",");
		return join(valuesArray);
	}
}
